import axios from 'axios'

    export var baseURL = 'http://59.110.27.137:8081'

 export const tokenLocalStorage = () => {
    return localStorage.getItem('Authorization')
 }

// create an axios instance
axios.defaults.headers['Content-Type'] = 'application/json'
const service = axios.create({
    baseURL: baseURL,
    timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
    config => {
        config.headers['Authorization'] = localStorage.getItem('Authorization')
        // // 是否需要设置 token
        // const isToken = (config.headers || {}).isToken === false
        // // 是否需要防止数据重复提交
        // const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
        // if (getToken() && !isToken) {
        //     config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
        // }
        // // get请求映射params参数
        // if (config.method === 'get' && config.params) {
        //     let url = config.url + '?' + tansParams(config.params);
        //     url = url.slice(0, -1);
        //     config.params = {};
        //     config.url = url;
        // }
        return config;
    },
    error => {
        console.log(error)
        return Promise.reject();
    }
);

// response interceptor
service.interceptors.response.use(
    /**
     * If you want to get http information such as headers or status
     * Please return  response => response
    */

    /**
     * Determine the request status by custom code
     * Here is just an example
     * You can also judge the status by HTTP Status Code
     */
    response => {
        return response.data;
    }
)

export default service
